home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / keyboard.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  3.4 KB  |  95 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. """Keyboard controls that don't map to menu items.  Right now this is just
  19. arrow keys, but it should be pretty easy to extend.
  20. """
  21.  
  22. import app
  23. import eventloop
  24. import tabs
  25.  
  26. UP = 1
  27. DOWN = 2
  28. LEFT = 3
  29. RIGHT = 4
  30. SPACE = 5
  31. ESCAPE = 6
  32. UNSUPPORTED = -1
  33.  
  34. @eventloop.asUrgent
  35. def handleKey(key, shiftDown, controlDown):
  36.     if app.controller.playbackController.currentItem is None:
  37.         handleKeyNoPlayback(key, shiftDown, controlDown)
  38.     else:
  39.         handleKeyPlayback(key, shiftDown, controlDown)
  40.  
  41. def handleKeyNoPlayback(key, shiftDown, controlDown):
  42.     if key not in (UP, DOWN):
  43.         return
  44.     if app.controller.selection.tabListActive:
  45.         selectionArea = app.controller.selection.tabListSelection
  46.         iterator = tabs.tabIterator()
  47.         area = 'tablist'
  48.     else:
  49.         selectionArea = app.controller.selection.itemListSelection
  50.         if selectionArea.currentView is None:
  51.             return
  52.         iterator = selectionArea.currentView
  53.         area = 'itemlist'
  54.     if key == UP:
  55.         toSelect = selectionArea.firstBeforeSelection(iterator)
  56.     else:
  57.         toSelect = selectionArea.firstAfterSelection(iterator)
  58.     if toSelect is not None:
  59.         if app.controller.selection.tabListActive:
  60.             itemView = tabs.getViewForTab(toSelect)
  61.         else:
  62.             itemView = selectionArea.currentView
  63.         app.controller.selection.selectItem(area, itemView, toSelect.getID(),
  64.                 shiftDown, controlDown)
  65.  
  66. def handleKeyPlayback(key, shiftDown, controlDown):
  67.     if key == RIGHT:
  68.         if controlDown:
  69.             app.controller.playbackController.skip(1)
  70.         else:
  71.             time = app.controller.videoDisplay.getCurrentTime()
  72.             if time is not None:
  73.                 time += 30.0
  74.                 if time < app.controller.videoDisplay.getDuration():
  75.                     app.controller.videoDisplay.setCurrentTime(time)
  76.     elif key == LEFT:
  77.         if controlDown:
  78.             app.controller.playbackController.skip(-1)
  79.         else:
  80.             time = app.controller.videoDisplay.getCurrentTime()
  81.             if time is not None:
  82.                 time -= 10.0
  83.                 if time > 0.0:
  84.                     app.controller.videoDisplay.setCurrentTime(time)
  85.     elif key == UP:
  86.         volume = app.controller.videoDisplay.getVolume()
  87.         app.controller.videoDisplay.setVolume(volume + 0.05)
  88.     elif key == DOWN:
  89.         volume = app.controller.videoDisplay.getVolume()
  90.         app.controller.videoDisplay.setVolume(volume - 0.05)
  91.     elif key == SPACE:
  92.         app.controller.playbackController.playPause()
  93.     elif key == ESCAPE:
  94.         app.controller.videoDisplay.exitFullScreen()
  95.